# Copyright (c) 2020-2021  Ltd

ARG BASE=golang:1.22
FROM ${BASE} AS builder

WORKDIR /file_server
# RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.ustc.edu.cn/g' /etc/apk/repositories
# RUN apk add --update --no-cache ${ALPINE_PKG_BASE} ${ALPINE_PKG_EXTRA}

COPY . .
RUN go env -w GOPROXY=https://goproxy.cn,direct GO111MODULE=on
RUN go mod tidy
RUN go mod download
RUN rm -rf fileserver
RUN go build -o fileserver cmd/fileServer.go


FROM golang:1.22

WORKDIR /file_server

COPY --from=builder /file_server/fileserver  /file_server/fileserver
COPY --from=builder /file_server/upload.gtpl  /file_server/upload.gtpl

RUN mkdir files
# alpine镜像使用的是musl libc而不是gun libc。因而动态链接库的位置不一致
#RUN mkdir /lib64 && ln -s /lib/libc.musl-x86_64.so.1 /lib64/ld-linux-x86-64.so.2
ENTRYPOINT ["/file_server/fileserver"]
CMD ["-dir", "/file_server/files","-port","8080"]

